In [34]:
import warnings
import datetime
import numpy as np
import pandas as pd
from evolutionary_computation.operators import *
import alphalens_rev as alphalens
In [35]:
warnings.filterwarnings('ignore')
In [36]:
df_pivot = pd.read_pickle(
"./evolutionary_computation/Data/df_pivot/df_pivot_5m.pkl")
require_cols = ['Open', 'High', 'Low', 'Close', 'Volume']
In [37]:
df_pivot = df_pivot.pivot(index="datetime", columns="asset")
# div(ts_min(df_pivot['Open'], 15), df_pivot['Close'])
factors = div(ts_mean(ts_std(df_pivot['Open'], 5), 15), df_pivot['Open'])
In [38]:
factors.index = pd.to_datetime(factors.index)
factors = factors[(factors.index.hour < 12)]
factors = factors[factors.index > "2018-12-14"]
factors.dropna(axis='columns', inplace=True)
pricing = df_pivot['Close']
pricing.index = pd.to_datetime(pricing.index)
pricing = pricing[pricing.index > "2018-12-14"]
In [39]:
def _validate_frequency(cls, index, freq, **kwargs):
return None
pd.core.arrays.datetimelike.DatetimeLikeArrayMixin._validate_frequency = _validate_frequency
non_predictive_factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factors.stack(),
pricing[factors.columns],
periods=(
6, 12),
quantiles=5)
Dropped 0.0% entries from factor data: 0.0% in forward returns computation and 0.0% in binning phase (set max_loss=0 to see potentially suppressed Exceptions).
max_loss is 35.0%, not exceeded: OK!
In [40]:
np.isinf(non_predictive_factor_data).values.sum()
Out[40]:
8
In [41]:
non_predictive_factor_data = non_predictive_factor_data.replace([np.inf, -np.inf], np.nan)
non_predictive_factor_data = non_predictive_factor_data.fillna(method='ffill')
np.isinf(non_predictive_factor_data).values.sum()
Out[41]:
0
In [42]:
alphalens.tears.create_full_tear_sheet(non_predictive_factor_data)
Quantiles Statistics
min max mean std count count %
factor_quantile
1 0.000000 0.013198 0.001033 0.000719 2089702 20.173478
2 0.000516 0.014903 0.001733 0.000956 2067239 19.956626
3 0.000802 0.016231 0.002328 0.001195 2067240 19.956635
4 0.001125 0.021325 0.003090 0.001490 2067239 19.956626
5 0.001521 1.073325 0.005206 0.003970 2067240 19.956635
Returns Analysis
30m 1h
Ann. alpha 956748.673 547.835
beta 0.404 0.380
Mean Period Wise Return Top Quantile (bps) -1.238 -1.318
Mean Period Wise Return Bottom Quantile (bps) 1.098 1.154
Mean Period Wise Spread (bps) -2.336 -2.475
<Figure size 432x288 with 0 Axes>
2021-08-27T10:26:20.060414 image/svg+xml Matplotlib v3.4.2, https://matplotlib.org/
Information Analysis
30m 1h
IC Mean -0.043 -0.059
IC Std. 0.178 0.179
Risk-Adjusted IC -0.243 -0.330
t-stat(IC) -36.435 -49.502
p-value(IC) 0.000 0.000
IC Skew -0.042 0.009
IC Kurtosis 0.590 0.826
2021-08-27T10:27:40.212598 image/svg+xml Matplotlib v3.4.2, https://matplotlib.org/